package com.sheledon.flyCat.core.resolver;

import com.sheledon.flyCat.annotation.springmvc.RequestParam;
import com.sheledon.flyCat.common.pojo.MethodDetail;
import com.sheledon.flyCat.common.utils.ObjectUtils;
import com.sheledon.flyCat.network.socket.http.HttpRequest;

import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.lang.reflect.Parameter;
import java.util.Map;
import java.util.Objects;

/**
 * @author sheledon
 */
public class RequestParamParameterResovler implements ParameterResolver{
    @Override
    public Object resolve(MethodDetail methodDetail, Parameter parameter) {
        RequestParam annotation = parameter.getAnnotation(RequestParam.class);
        String name = annotation.name();
        if (!"".equals(name)){
            Map<String,String> queryParamsMap = methodDetail.getQueryParamsMap();
            if (Objects.isNull(queryParamsMap)){
                return null;
            }
            String value = queryParamsMap.get(name);
            return ObjectUtils.convert(parameter.getType(),value);
        }
        return null;
    }
}
